package heven.holt.wan.android.model

import android.os.Parcel
import android.os.Parcelable
import kotlinx.parcelize.Parcelize

//@Parcelize
//当使用Parcelize时，无法获取CREATOR伴生类，等待google解决
//https://youtrack.jetbrains.com/issue/KT-19853
//https://github.com/JetBrains/kotlin/pull/4575
data class UserModel(
    val admin: Boolean?,
    val coinCount: Int?,
    val email: String?,
    val icon: String?,
    val id: Int?,
    val nickname: String?,
    val password: String?,
    val publicName: String?,
    val token: String?,
    val type: Int?,
    val username: String?
) : Parcelable {
    constructor(parcel: Parcel) : this(
        parcel.readValue(Boolean::class.java.classLoader) as? Boolean,
        parcel.readValue(Int::class.java.classLoader) as? Int,
        parcel.readString(),
        parcel.readString(),
        parcel.readValue(Int::class.java.classLoader) as? Int,
        parcel.readString(),
        parcel.readString(),
        parcel.readString(),
        parcel.readString(),
        parcel.readValue(Int::class.java.classLoader) as? Int,
        parcel.readString()
    ) {
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeValue(admin)
        parcel.writeValue(coinCount)
        parcel.writeString(email)
        parcel.writeString(icon)
        parcel.writeValue(id)
        parcel.writeString(nickname)
        parcel.writeString(password)
        parcel.writeString(publicName)
        parcel.writeString(token)
        parcel.writeValue(type)
        parcel.writeString(username)
    }

    override fun describeContents(): Int {
        return 0
    }

    companion object CREATOR : Parcelable.Creator<UserModel> {
        override fun createFromParcel(parcel: Parcel): UserModel {
            return UserModel(parcel)
        }

        override fun newArray(size: Int): Array<UserModel?> {
            return arrayOfNulls(size)
        }
    }
}